package com.example.translateappjava.Service.CalculateRalate;

import android.graphics.Bitmap;

public class Calculate {
    /**
     * 这里是计算BMI体质指数的,所有统一以厘米为单位
     * @param kilo
     * @param height
     * @return
     */
    public String bodyMassIndex(double kilo,double height)
    {
        height = height/100;
        double BMI = kilo/(height*height);
        return String.valueOf(BMI);
    }

    /**
     * 这里是计算体脂率的
     * @param kilo
     * @param height
     * @param age
     * @param man
     * @return
     */
    public String bodyFatPercentage(double kilo,double height,int age,boolean man)
    {
        double BFP;
        if (man){
            BFP = 1.2 * Double.parseDouble(bodyMassIndex(kilo,height)) + 0.23 * age -16.2;
        }
        else {
            BFP = 1.2 * Double.parseDouble(bodyMassIndex(kilo,height)) + 0.23 * age -5.4;
        }
        return String.valueOf(BFP);
    }

    /**
     * 这里是计算基础代谢率的
     * level代表的是运动等级
     * 1 久坐（很少运动）：BMR × 1.2
     * 2 轻度活动（每周运动1-3天）：BMR × 1.375
     * 3 中度活动（每周运动3-5天）：BMR × 1.55
     * 4 重度活动（每周运动6-7天）：BMR × 1.725
     * 5 极重度活动（每天运动或体力劳动）：BMR × 1.9
     * @param kilo
     * @param height
     * @param age
     * @param man
     * @return
     */
    public String basalMetabolicRate(double kilo,double height,int age,boolean man)
    {
        double BMR;
        if (man)
        {
            BMR=88.362+(13.397 * kilo)+(4.799 * height)-(5.677 * age);
        }
        else
        {
            BMR=447.593+(9.247 * kilo) + (3.098 * height)-(4.330 * age);

        }
        return String.valueOf(BMR);
    }

    /**
     * 这里是计算每日的基础热量的
     * @param kilo
     * @param height
     * @param age
     * @param man
     * @param level
     * @return
     */
    public String totalDailyEnergyExpenditure(double kilo,double height,int age,boolean man,int level)
    {
        double TDEE;
        switch (level)
        {
            case 1:
                TDEE = Double.parseDouble(basalMetabolicRate(kilo, height, age, man)) * 1.2;
                break;
            case 2:
                TDEE = Double.parseDouble(basalMetabolicRate(kilo, height, age, man)) * 1.375;
                break;
            case 3:
                TDEE = Double.parseDouble(basalMetabolicRate(kilo, height, age, man)) * 1.55;
                break;
            case 4:
                TDEE = Double.parseDouble(basalMetabolicRate(kilo, height, age, man)) * 1.725;
                break;
            case 5:
                TDEE = Double.parseDouble(basalMetabolicRate(kilo, height, age, man)) * 1.9;
                break;
            default:
                return "Invalid activity level";
        }
        return  String.valueOf(TDEE);
    }
}
